/**
 * Created by Rinvay on 10/02/21.
 */

/**
 * @param {string} path
 * @returns {Boolean}
 */
export function isExternal(path) {
  return /^(https?:|mailto:|tel:)/.test(path)
}

/**
 * @param {string} str
 * @returns {Boolean}
 */
export function validUsername(str) {
  const valid_map = ['admin', 'editor', 'rinvay']
  return valid_map.indexOf(str.trim()) >= 0
}

// 身份证校验
export const vaildQQ = (qq) => {
  let reg = /^[1-9][0-9]{4,12}$/
  return reg.test(qq)
}

// 邮箱验证
export const vaildEmail = (email) => {
  let reg = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/
  return reg.test(email)
}

// 网站验证
export const vaildWebsite = (website) => {
  let reg = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\*\+,;=.]+$/
  return reg.test(website)
}
